package com.apts.model;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;

public class TBpe extends Model<TBpe> {
	private static final long serialVersionUID = 1L;

	public static final TBpe dao = new TBpe();

	// 查找某一类型对应多的企业（注册号以及公司名）
	public List<TBpe> PEFindenterprise(String typecode) {
		String sql = "select * from pe where typecode=? ";
		System.out.println("typecode是：" + typecode);
		List<TBpe> tbpe = TBpe.dao.find(sql, typecode);
		return tbpe;
	}

	// 根据类型编号精确查找
	public TBpe PEFindbytypecode(String typecode) {
		String sql = "select * from pe where typecode=? ";
		TBpe tbpe = TBpe.dao.findFirst(sql, typecode);
		return tbpe;
	}

	public List<TBpe> PEFindbyepname(String epname) {
		String sql = "select distinct typecode from pe where epname=? ";
		List<TBpe> tbpe = TBpe.dao.find(sql, epname);
		return tbpe;
	}

	// 向产品类型添加公司
	public void PEadd(String typecode, String regcode) {
		TbEnterprise enterprise = TbEnterprise.dao.findById(regcode);
		String epname = enterprise.getStr("epname");
		TBpe tbpe = new TBpe();
		tbpe.set("typecode", typecode).set("regcode", regcode).set("epname", epname).save();
	}

	// 删除某企业的某类品种
	public void PEdelete(String typecode, String regcode) {
		String sql1 = "delete from pe where typecode=? and regcode=? ";
		Db.update(sql1,typecode,regcode);
	}

}
